package com.sgb.jicai.view.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.sgb.jicai.BR;
import com.sgb.jicai.R;
import com.sgb.jicai.entity.JcMyCenterXufangFaQiEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import java.util.List;

/**
 * 个人中心需方发起adapter
 */
public class CenterXuFangFaQiAdapter extends BaseRecycleAdapter<JcMyCenterXufangFaQiEntity> {
    private OnItemMangage onitemmangage;

    public CenterXuFangFaQiAdapter(Context context, List<JcMyCenterXufangFaQiEntity> datas) {
        super(context, R.layout.item_center_xufangfaqi, datas);
    }

    @Override
    public void onBindViewHolder(ItemViewHolder holder, int position) {
        super.onBindViewHolder(holder, position);
        TextView  tvStop = holder.getItem().findViewById(R.id.tv_stop);
        TextView  tvDelete = holder.getItem().findViewById(R.id.tv_delete);
        //需方发起--停止集采
        tvStop.setOnClickListener(view -> {
            if (onitemmangage != null) {
                onitemmangage.stop(datas.get(position).getNo());
            }
        });
        //需方发起--删除集采订单
        tvDelete.setOnClickListener(view -> {
            if (onitemmangage != null) {
                onitemmangage.Delete(datas.get(position).getNo());
            }
        });
    }

    @Override
    public void convert(ItemViewHolder holder, final JcMyCenterXufangFaQiEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        TextView tvGroupBuyType = holder.getItem().findViewById(R.id.tv_group_buy_type);
        TextView  tvTwoType = holder.getItem().findViewById(R.id.tv_two_type);
        TextView tvQuotationType = holder.getItem().findViewById(R.id.tv_quotation_type);
        ImageView stateImg = holder.getItem().findViewById(R.id.state_img);
        LinearLayout  llXffq = holder.getItem().findViewById(R.id.ll_xffq);
        TextView  tvStop = holder.getItem().findViewById(R.id.tv_stop);
        TextView  tvDelete = holder.getItem().findViewById(R.id.tv_delete);
        TextView  tvJoinType = holder.getItem().findViewById(R.id.tv_join_type);
        if ("1".equals(entity.getGroupbuyType()) || "3".equals(entity.getGroupbuyType())) {//即报集采  或者  企业专项
            if (entity.getStatus().equals("1")) {//进行中
                tvStop.setVisibility(View.VISIBLE);
                tvDelete.setVisibility(View.GONE);
            } else {
                tvStop.setVisibility(View.GONE);
                tvDelete.setVisibility(View.VISIBLE);
            }
        } else if ("2".equals(entity.getGroupbuyType())) {//汇集采购
            if (entity.getStatus().equals("1")) {//进行中
                tvStop.setVisibility(View.VISIBLE);
                tvDelete.setVisibility(View.GONE);
            } else {
                tvStop.setVisibility(View.GONE);
                tvDelete.setVisibility(View.VISIBLE);
            }
        }
        if (entity.getStatus().equals("8")||entity.getStatus().equals("9")){
            tvStop.setVisibility(View.GONE);
            tvDelete.setVisibility(View.GONE);
        }
        switch (entity.getStatus()) {//状态  1 进行中2 已完成  3集采作废   4集采失败  5 加盟中 6 报价中
            case "1":
                stateImg.setImageResource(R.mipmap.collect_ing);
                break;
            case "2":
                stateImg.setImageResource(R.mipmap.collect_complate);
                break;
            case "3":
                stateImg.setImageResource(R.mipmap.jc_jczf);
                break;
            case "4":
                stateImg.setImageResource(R.drawable.collect_fail);
                break;
            case "5":
                stateImg.setImageResource(R.mipmap.jc_to_join);
                break;
            case "6":
                stateImg.setImageResource(R.mipmap.jc_bjz);
                break;
            case "8":
                stateImg.setImageResource(R.mipmap.jc_spz);
                break;
            case "9":
                stateImg.setImageResource(R.mipmap.jc_yjj);
                break;
        }
        switch (entity.getGroupbuyType()) {//1即报集采  2汇总集采  3企业专项
            case "1":
                tvGroupBuyType.setBackgroundResource(R.mipmap.jbjc);
                tvGroupBuyType.setText(R.string.jbjc);
                break;
            case "2":
                tvGroupBuyType.setBackgroundResource(R.mipmap.hzcg);
                tvGroupBuyType.setText(R.string.hzcg);
                break;
            case "3":
                tvGroupBuyType.setBackgroundResource(R.mipmap.qyzx);
                tvGroupBuyType.setText(R.string.qyzx);
                break;
        }

        switch (entity.getGroupbuyClass()) { //第二类型标签     //报价类型: 1：商品材料   2：机械租赁  3：设备租赁
            case "1":
                tvTwoType.setVisibility(View.VISIBLE);
                tvTwoType.setText("商品材料");
                tvTwoType.setBackgroundResource(R.drawable.shape_blue_button);
                break;
            case "2":
                tvTwoType.setVisibility(View.VISIBLE);
                tvTwoType.setText("机械租赁");
                tvTwoType.setBackgroundResource(R.drawable.shape_blue_button);
                break;
            case "3":
                tvTwoType.setVisibility(View.VISIBLE);
                tvTwoType.setText("设备租赁");
                tvTwoType.setBackgroundResource(R.drawable.shape_blue_button);
                break;
            default:
                tvTwoType.setVisibility(View.GONE);
                break;
        }
        switch (entity.getOfferType()) {//报价类型: 0：市场报价   1：会员报价
            case "1":
                tvQuotationType.setVisibility(View.VISIBLE);
                tvQuotationType.setText("客户报价");
                tvQuotationType.setTextColor(context.getResources().getColor(R.color.color_FDA72D));
                tvQuotationType.setBackgroundResource(R.drawable.bg_market_join_price);
                break;
            case "2":
                tvQuotationType.setVisibility(View.VISIBLE);
                tvQuotationType.setTextColor(context.getResources().getColor(R.color.color_0286DF));
                tvQuotationType.setText("市场报价");
                tvQuotationType.setBackgroundResource(R.drawable.bg_marketprice);
                break;
            case "3":
                tvQuotationType.setVisibility(View.VISIBLE);
                tvQuotationType.setTextColor(context.getResources().getColor(R.color.color_FF4B10));
                tvQuotationType.setText("成员报价");
                tvQuotationType.setBackgroundResource(R.drawable.bg_memberoffer);
                break;
            default:
                tvQuotationType.setVisibility(View.GONE);
                break;
        }
        //加盟客户类型
        switch (entity.getJoinType()) {//1、市场加盟 2、会员加盟 3、成员加盟
            case "1":
                tvJoinType.setVisibility(View.VISIBLE);
                tvJoinType.setTextColor(context.getResources().getColor(R.color.color_FDA72D));
                tvJoinType.setText("客户加盟");
                tvJoinType.setBackgroundResource(R.drawable.bg_market_join_price);

                break;
            case "2":
                tvJoinType.setVisibility(View.VISIBLE);
                tvJoinType.setText("市场加盟");
                tvJoinType.setTextColor(context.getResources().getColor(R.color.color_0286DF));
                tvJoinType.setBackgroundResource(R.drawable.bg_marketprice);
                break;
            case "3":
                tvJoinType.setVisibility(View.VISIBLE);
                tvJoinType.setTextColor(context.getResources().getColor(R.color.color_FF4B10));
                tvJoinType.setText("成员加盟");
                tvJoinType.setBackgroundResource(R.drawable.bg_memberoffer);
                break;
            default:
                tvJoinType.setVisibility(View.GONE);
                break;
        }

    }

    public void setOnItemMangage(OnItemMangage onitemmangage) {
        this.onitemmangage = onitemmangage;

    }

    public interface OnItemMangage{
        void stop(String id);
        void Delete(String id);
    }
}
